<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<pre>
    将中缀表达式（op1 operator op2）转换为后缀表达式（op1 op2 operator），并求值
</pre>
<script>
    function Stack(){
        this.data=[];
        this.top=0;
    }
    Stack.prototype={
        constructor:Stack,
        push: function (elm) {
            this.data[this.top++]=elm;
        },
        pop: function () {
            return this.data[--this.top];
        },
        peek: function () {
            return this.data[this.top-1];
        },
        size: function () {
            return this.top;
        },
        clear: function () {
            delete this.data;
            this.data=[];
            this.top=0;
        }
    }

    function convert(op1,operator,op2){
        var s=new Stack(),exp='',r='';
        s.push(op1);
        s.push(op2);
        s.push(operator);
        r=new Function('return ('+op1+operator+op2+')')();
        console.log('exp:', s.data.join(' '),exp,'\nresult:',r);
    }
    convert(1,'+',2);

</script>
</body>
</html>